<template>
	<view>
		<view class="page">
			<view class="top">
				<view class="tabbar-title" :style="{'paddingTop': tabbarTop}">
					<view class="flex align-center" @click="back" :style="{'height': height,'width': height}">
						<view class="icon">
							<image src="https://sanfuzhide.oss-cn-hangzhou.aliyuncs.com/circle/linkbank.png" mode="">
							</image>
						</view>
					</view>
				</view>
				<image class="img" src="https://sanfuzhide.oss-cn-hangzhou.aliyuncs.com/vip/%E4%B8%93%E5%AE%B6%E4%BF%AE%E6%94%B9%E7%AE%80%E5%8E%86%402x_%E5%A5%BD%E5%8E%8B%E7%9C%8B%E5%9B%BE.png"></image>
			</view>
			<view class="contnent">
				<view class="txt">
					选择购买服务
				</view>
				<view class="list">
					<view v-for="item in list" :key="item.resumeServiceId" class="content">
						<view :class="show == item.resumeServiceId?'select':'selec'" @click="select(item)">
							<view class="title">
								{{item.resumeServiceName}}
							</view>
							<view class="money">
								<view class="number">
									{{item.payAmount}}
								</view>
								<view class="yuan">元</view>
							</view>
						</view>
					</view>
				</view>
				<view class="buy-button" @click="submit">
					立即购买
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list: [],
				show: 0,
				selectQurey:{
					body:'',
					openid:'',
					resumeServiceId:'',
					totalFee:''
				},
				height: 0,
				tabbarTop: 0
			}
		},
		onLoad() {
			this._setTabbarTitleHeight()
			this.getData()
		},
		methods:{
			async submit() {
				let {data,code} = await this.$post('/payOrder/getPayOrder',this.selectQurey)
				if(code == 200){
					uni.requestPayment({
					    provider: 'wxpay',
					    timeStamp: data.pay.timestamp,
					    nonceStr: data.pay.noncestr,
					    package:'prepay_id=' + data.pay.prepayid,
					    signType: 'MD5',
					    paySign: data.pay.paySign,
					    success: function (res) {
							uni.showToast({
								title: '支付成功,请联系客服',
								icon: 'none',
								duration: 2000
							})
							const fn = function() {
								uni.navigateTo({
									url: '../../pagesA/serviceCenter/serviceCenter',
								})
							}
							setTimeout(fn,2000)
					    },
					    fail: function (err) {
							uni.showToast({
								title:'支付失败，请稍后再试',
								icon:'none'
							})
					    }
					});
				}
			},
			select(e){
				this.show = e.resumeServiceId
				this.selectQurey.body = e.resumeServiceName
				this.selectQurey.resumeServiceId = e.resumeServiceId
				this.selectQurey.totalFee = e.payAmount
			},
			async getData() {
				let {data,code} = await this.$get('/userResumeList/resumeServiceList')
				if(code == 200){
					this.list = data
				}
			},
			_setTabbarTitleHeight() {
				let top = uni.getStorageSync('tabbarCapsule')
				this.tabbarTop = top.top + 'px'
				this.height = top.height + 'px'
				this.piddheight = top.height + top.top + 'px'
			},
			back() {
				uni.navigateBack({
					delta: 0
				})
			},
		}
	}
</script>

<style lang="scss">
	.page {
		.top {
			width: 100%;
			height: 341rpx;
			.icon {
				width: 38rpx;
				height: 38rpx;
				margin-left: 20rpx;
				z-index: 99;
			}
			.img {
				width: 100%;
				height: 341rpx;
				position: absolute;
				top:0;
				}
		}

		.contnent {
			border-top-left-radius: 34rpx;
			border-top-right-radius: 34rpx;
			// border-top: 1rpx solid #000000;
			position: relative;
			background-color: #FFFFFF;
			bottom: 32rpx;
			padding: 47rpx 35rpx 91rpx 35rpx;
			z-index: 99;
			.txt {
				font-size: 33rpx;
				font-weight: bold;
			}

			.list {
				padding-top: 40rpx;

				.select {
					margin-bottom: 34rpx;
					border-radius: 18rpx;
					width: 682rpx;
					height: 110rpx;
					border: 3rpx solid #0067F4;
					display: flex;
					align-items: center;
					position: relative;	
					background-color: #F5F9FF;
					.title {
						padding-left: 24rpx;
						font-size: 28rpx;
					}

					.money {
						display: flex;
						position: absolute;
						right: 25rpx;
						align-items: center;
						.number {
							font-size: 40rpx;
							font-weight: bold;
							color: #FD4E4E;
							padding-right: 12rpx;
						}

						.yuan {
							font-size: 22rpx;
							color: #FD4E4E;
						}
					}
				}

				.selec {
					margin-bottom: 34rpx;
					border-radius: 18rpx;
					width: 682rpx;
					height: 110rpx;
					border: 3rpx solid #E5E5E5;
					display: flex;
					align-items: center;
					position: relative;	
					background-color: #FFFFFF;
					.title {
						padding-left: 24rpx;
						font-size: 28rpx;
					}
				
					.money {
						display: flex;
						position: absolute;
						right: 25rpx;
						align-items: center;
						.number {
							font-size: 40rpx;
							font-weight: bold;
							color: #FD4E4E;
							padding-right: 12rpx;
						}
				
						.yuan {
							font-size: 22rpx;
							color: #FD4E4E;
						}
					}
				}

			}
			.buy-button{
				background-color: #0067F4;
				width: 690rpx;
				height: 90rpx;
				border-radius: 45rpx;
				color:#fff;
				display: flex;
				justify-content: center;
				align-items: center;
				font-size: 32rpx;
				position: fixed;
				left:30rpx;
				bottom:calc(89rpx + env(safe-area-inset-bottom));
			}
		}

	
	}
</style>
